package com.bw.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAop {

    @Around("execution(* com.bw.controller.*.*(..))")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getSignature().getName();
        System.out.println("方法名" + name);
        Object[] args = joinPoint.getArgs();
        System.out.println("方法的入参 " +args);
        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long l2 = System.currentTimeMillis();
        System.out.println("返回值 " + JSON.toJSONString(proceed));

        // {方法名称}，执行时间{时间}毫秒
        System.out.println("方法名：" + name + " 执行时间： " + (l2-l) +"毫秒");

        return proceed;


    }

}
